package cn.stylefeng.guns.sys.modular.system.quartz.task;

import cn.stylefeng.guns.sys.core.util.DateUtil;
import cn.stylefeng.guns.sys.modular.system.service.DsstoreBillService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

//作业不并发
@DisallowConcurrentExecution
@Component
public class DsstorebillDataJob implements Job {
    private Logger logger = LoggerFactory.getLogger(DsstorebillDataJob.class);
    @Resource
    private DsstoreBillService dsstoreBillService;

    @Override
    public void execute(JobExecutionContext arg0) {
        //每天凌晨3点获取前一天的数据入库
        try {
            Date date = new Date();
            String yearstoday = DateUtil.getYearstoday(date);
            List<String> dateList = new ArrayList<>();
            dateList.add(yearstoday);
            dateList.add(DateUtil.getNowDate());
            logger.info("门店库存流水定时任务-开始执行数据写入,日期：{}", dateList.toString());
            Map<String, Integer> map = dsstoreBillService.initDsstorebillData(dateList);
            logger.info("门店库存流水定时任务-结束执行数据写入,{}", map.toString());
        } catch (Exception e) {
            logger.info("门店库存流水定时任务，写入数据失败");
            e.printStackTrace();
        }
    }
}